package com.keson.spider;
import java.awt.print.PageFormat;
import java.awt.print.Paper;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

import com.spire.doc.Document;
public class WordPrintUtil {

	public static void print(String path) {
		//加载文档
        Document doc = new Document();
        doc.loadFromFile(path);

        PrinterJob loPrinterJob = PrinterJob.getPrinterJob();
        PageFormat loPageFormat = new PageFormat();
        loPageFormat.setOrientation(PageFormat.PORTRAIT);
        //设置打印纸张大小
        Paper loPaper = loPageFormat.getPaper();
        loPaper.setSize(590, 840);
        //删除默认页边距
        loPaper.setImageableArea(0,0, 590, 840);
        
        
        loPageFormat.setPaper(loPaper);
        //设置打印份数
        loPrinterJob.setCopies(1);
        loPrinterJob.setPrintable(doc, loPageFormat);
        //设置打印对话框
//        if (loPrinterJob.printDialog()) {
            //执行打印
            try {
                loPrinterJob.print();
            } catch (PrinterException e){
                e.printStackTrace();
            }
//        }
	}
}
